package algorithm.leetcode;

/**
 * @program: util
 * @description: 合法的括号
 * @author: zhouliangliang
 * @create: 2021-04-12 19:52
 **/
public class ParenthesesGenerate {

    private void generate(String parent, int left, int right, int n) {
        if(parent.length() == 2 * n) {
            System.out.println(parent);
        }

        if(left < n) {
             generate(parent + "(" , left+1, right, n);
        }

        if(right < left) {
             generate(parent + ")", left, right+1, n);
        }
    }

    public static void main(String[] args) {
        new ParenthesesGenerate().generate("", 0,0, 3);
    }
}
